﻿Imports System.Runtime.CompilerServices
Imports AdvanceWars.Data

Module UnitHelper

    ''' <summary>
    ''' 判断单位是否能攻击 并返回使用的武器
    ''' </summary>
    <Extension()>
    Public Function CanFire(ByVal atkUnit As Unit, ByVal defUnitId As Integer) As Weapon
        Dim w1 As Weapon = atkUnit.Base.PrimaryWeapon
        Dim w2 As Weapon = atkUnit.Base.SecondaryWeapon
        If w1.Ammo.Value > 0 Then
            If DataService.GetDamage(w1.Type.Id, defUnitId) > 0 Then
                Return w1
            End If
        ElseIf DataService.GetDamage(w2.Type.Id, defUnitId) > 0 Then
            Return w2
        End If
        Return Nothing
    End Function

End Module
